#include "dataencodings.h"

#include <bitset>

#include <QTextCodec>
#include <QByteArray>

namespace qrcode {


DataEncodings::DataEncodings()
{

}

std::vector<char> DataEncodings::GetECIIndicator(int ECICode)
{
    std::vector<char> indicator = {'0', '1', '1', '1'};

    std::vector<char> assignment = GetECIAssignmentNumber(ECICode);

    for(int i = 0; i < assignment.size(); i++){
        indicator.push_back(assignment.at(i));
    }

    return indicator;

}

void DataEncodings::ConvertCode(std::__cxx11::string &msg, int &ECICode)
{
    std::string codec = ToEncodingStr(ECICode);

    QTextCodec *utf8Codec = QTextCodec::codecForName("UTF-8");
    QTextCodec *Codec = QTextCodec::codecForName("UTF-8");

    QByteArray bytes = Codec->fromUnicode(utf8Codec->toUnicode(msg.data()));

    msg = bytes.data();
}

std::vector<char> DataEncodings::GetECIAssignmentNumber(int &ECICode)
{
    std::vector<char> assignment;

    std::bitset<8> bits = ECICode;
    std::string str = bits.to_string();

    for(int i = 0; i < str.length(); i++){
        assignment.push_back(str.at(i));
    }

    return assignment;
}

std::__cxx11::string DataEncodings::ToEncodingStr(int &ECICode)
{
    std::string codec;

    return codec;
}

}
